package com.sztz.batch;

import com.sztz.service.UserTestService;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.lang.Nullable;

/**
 * 添加User的SpringBatch小任务
 * @author yzy
 * @date 2022/8/25 17:18
 */
public class AddUserTasklet implements Tasklet {
    /**
     * 用户处理服务
     */
    private UserTestService userService;
    /**
     * 文件路径
     */
    private String filePath;
    /**
     * 调用用户服务的批量导入用户功能
     * @param contribution
     * @param chunkContext
     * @return RepeatStatus
     * @throws Exception
     * @author yzy
     * @date 2022/8/25 17:18
     */
    @Nullable
    @Override
    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
        userService.importUserFromExcel(filePath);
        return RepeatStatus.FINISHED;
    }

    public void setFilePath(String filePath){
        this.filePath = filePath;
    }
    public void setUserService(UserTestService userService){
        this.userService = userService;
    }
}
